#ifndef _GRAPHICS_UTIL_
#define _GRAPHICS_UTIL_

#include "graphics.h"
#include "math/vec4.h"
#include "math/spline2d.h"
class GraphicsUtil
{
public:
	// helper functions... is there a better place for them?
	static int		FillQuad(Graphics::Vertex2D*	Quad, Graphics::Vertex2D*	VertA);
	static int		FillQuad(math::Vec2* PosA, math::Vec2* UVA, COLOR* ColorA, Graphics::Vertex2D*	VertA);
	static int		FillQuad(	const math::Vec2& Pos, const math::Vec2& Size, 
								const math::Vec2& UV1,const math::Vec2& UV2,
								COLOR	c, 
								Graphics::Vertex2D*	VertA);
	static int		FillQuad(	const math::Vec2& Pos, const math::Vec2& Size, 
								const math::Vec2& UV1,const math::Vec2& UV2,
								COLOR	c0, COLOR c1, COLOR c2, COLOR c3,
								Graphics::Vertex2D*	VertA);

	static int 		FillRotQuad(	
								const math::Vec2& Pos, const math::Vec2& Size, float Rot,
								const math::Vec2& UV1,const math::Vec2& UV2,
								COLOR	c, 
								Graphics::Vertex2D*	VertA);

	static int		FillRotatedQuad(	
								int	Rotation,
								const math::Vec2& Pos, const math::Vec2& Size, 
								const math::Vec2& UV1,const math::Vec2& UV2,
								COLOR	c, 
								Graphics::Vertex2D*	VertA);

	static int		FillLine(const math::Vec2& From, const math::Vec2& To, float Radius, COLOR c0, COLOR c1,  const math::Vec2& UV1, const math::Vec2& UV2, Graphics::Vertex2D*	VertA);
	static int		FillLine(const math::Vec2& From, const math::Vec2& To, float Radius, COLOR c0, COLOR c1, Graphics::Vertex2D*	VertA);
	static int		FillCapsule(const math::Vec2& From, const math::Vec2& To, float Radius, COLOR c0, COLOR c1, Graphics::Vertex2D*	VertA);
	static int		FillCircle(const math::Vec2& Pos, float Radius, COLOR c0, COLOR c1,  Graphics::Vertex2D*	VertA);
	static int		FillPath(const math::Vec2& Offset, float Scale, const math::Vec2* LineA, int LineC, float Radius, Graphics::Vertex2D*	VertA, int Max);
	static int		FillPath(const math::Vec2& Offset, float Scale, const math::Vec2* LineA, int VertC, const math::Vec2& MinUV, const math::Vec2& MaxUV,  const math::Vec4& FromCol, const math::Vec4& ToCol, float FromW, float ToW, Graphics::Vertex2D*	VertA, int Max);
	static int		FillSpline(const math::Vec2& Offset, float Scale, math::SplineCache2D* pSpline, float UVOffset, float UVMult, float Width, Graphics::Vertex2D*	VertA, int Max);

	static bool		CopyBufferRect(void* pBuffer, const void* pSrc, unsigned int Width, unsigned int Height, unsigned int Pitch, unsigned int PixelSize = 4);

	static void		EnableSnapToPixel(bool bSnap = true) { SnapToPixel = bSnap; }
	static void		SetWindowSize(unsigned int Width, unsigned int Height) {
						WIDTH = Width;
						HEIGHT = Height;
						H2W = (float)Height / (float)Width;
						W2H = (float)Width / (float)Height;
						InvW = 1.0f / (float)Width;
						InvH = 1.0f / (float)Height;
	}
	static void		SnapPosToAbsPixel(math::Vec2& Pos) {
						Pos.x = InvW * floor((Pos.x * WIDTH) + 0.5f);
						Pos.y = InvH * floor((Pos.y * HEIGHT) + 0.5f);
	}


	static  float		H2W;
	static	float		W2H;
	static	float		InvW;
	static	float		InvH;
	static	unsigned int	WIDTH;
	static	unsigned int	HEIGHT;
	static	bool		SnapToPixel;

	static const float	PT_OFFSET;
};
#endif // _GRAPHICS_UTIL_